import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.*;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class send implements Runnable{
    DatagramSocket datagramSocket=null;
    BufferedReader bufferedReader=null;
    private int portFrom;
    private int portTo;
    private String ip;
    public send(String ip,int portFrom,int portTo){
        this.portFrom=portFrom;
        this.portTo=portTo;
        this.ip = ip;
        try {
            this.datagramSocket = new DatagramSocket(portFrom);
            this.bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void run() {
        while (true){
            try {
                String string = bufferedReader.readLine();
                DatagramPacket datagramPacket = new DatagramPacket(string.getBytes(StandardCharsets.UTF_8), string.length(), new InetSocketAddress(this.ip, this.portTo));
                datagramPacket.getData();
                datagramSocket.send(datagramPacket);
                if( string.equals("bye")){
                    break;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
